package com.zmn.oms.dubbo.impl.zmn.normal.report;

import org.apache.dubbo.config.annotation.Service;
import com.google.common.collect.Lists;
import com.zmn.common.dto.ResponseDTO;
import com.zmn.common.utils.reflect.BeanMapper;
import com.zmn.common.utils.response.ResponseUtil;
import com.zmn.oms.dubbo.dto.zmn.report.ComplaintDIO;
import com.zmn.oms.dubbo.dto.zmn.report.ComplaintDRO;
import com.zmn.oms.dubbo.interfaces.zmn.normal.report.ZsNormalUmsComplaintReportRemoteService;
import com.zmn.oms.dubbo.utils.DubboConsts;
import com.zmn.oms.model.entity.report.ComplaintReportOrderCount;
import com.zmn.oms.model.entity.report.ComplaintReportQuery;
import com.zmn.oms.services.interfaces.report.ReportUmsComplaintService;
import org.apache.commons.beanutils.BeanUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import javax.xml.ws.Response;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * 类描述: UMS投诉报表订单信息接口实现
 *
 * @author mujunlin
 * @date 2019/05/06 10:26
 */
@Service(loadbalance = "roundrobin", timeout = 5000, retries = 2, version = DubboConsts.INTERFACE_VERSION, validation = "false")
public class ZsNormalUmsComplaintReportRemoteServiceImpl implements ZsNormalUmsComplaintReportRemoteService {

    static final String TAG = "啄木鸟-UMS-投诉报表";

    private Logger logger = LoggerFactory.getLogger(ZsNormalUmsComplaintReportRemoteServiceImpl.class);

    @Autowired
    private ReportUmsComplaintService complaintService;

    @Override
    public ResponseDTO<ComplaintDRO> listComplaintOrderByQuery(ComplaintDIO complaintDIO) {
        try {
            ComplaintReportQuery query = new ComplaintReportQuery();
            BeanMapper.copy(complaintDIO, query);
            List<ComplaintReportOrderCount> complaintReportOrderCounts = complaintService.listByQuery(query);
            List<ComplaintDRO> complaintDROS = BeanMapper.mapList(complaintReportOrderCounts, ComplaintDRO.class);
            return ResponseUtil.responseSuccessItems(complaintDROS);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseUtil.responseFail(e.getMessage());
        }
    }
}
